package cn.hinglo.common.plugin.mongodb;

import com.jfinal.plugin.IPlugin;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;

/**
 * @createTime: 2019/1/11
 * @author: HingLo
 * @description: mongodb插件
 */
public class MongoDbPlugin implements IPlugin {
    private static MongoClient client;

    /**
     * 链接信息
     *
     * @param url      链接url
     * @param database 默认数据
     */
    public MongoDbPlugin(String url, String database) {
        client = MongoClients.create(url);
        MongoDbKit.init(client, database);
    }

    /***
     * 链接信息
     * @param url 链接url
     */
    public MongoDbPlugin(String url) {
        MongoDbKit.init(MongoClients.create(url), null);
    }

    /**
     * 创建默认的信息
     */
    public MongoDbPlugin() {
        MongoDbKit.init(MongoClients.create(), null);
    }


    @Override
    public boolean start() {
        return true;
    }

    @Override
    public boolean stop() {
        return true;
    }
}
